package com.example.mybaties;

import com.example.mybaties.mapper.UserMapper;
import com.example.mybaties.model.UserInfo;
import jakarta.annotation.Resource;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.ibatis.session.defaults.DefaultSqlSessionFactory;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;


import java.io.IOException;
import java.io.Reader;
//
//@SpringBootTest
public class UserTset {
//
    @Test
    public void userFindByIdTest() {
//  xml没错，是注释的这段代码有问题了， 正确写法应该是我这种，
        String resouces = "mybatis-config.xml";
        Reader reader = null;
        try{
            reader = Resources.getResourceAsReader(resouces);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        SqlSessionFactory sqlMapper = new SqlSessionFactoryBuilder().build(reader);
        SqlSession session = sqlMapper.openSession();

        UserInfo userinfo = session.selectOne("selectId","2022131495");
        System.out.println(userinfo);
        session.close();

//        userMapper.selectId(2022131139);
    }
}
